#ifndef SERIALPORTSQLDB_H
#define SERIALPORTSQLDB_H
#include <QSqlDatabase>
#include <QSqlRecord>
#include <QSqlQuery>
#include <QSettings>
#include "serialportconfig.h"
#include "serialportdefine.h"

class SerialportSqldb
{
public:
    SerialportSqldb();
    ~SerialportSqldb();

public:
    QString databaseName;//数据库名字

    bool reOpenSql();//打开连接
    bool closeSql();//关闭连接
    bool addData(QString tableName,QHash<QString,QVariant> data);//增加
    bool updateData(QString tableName,QHash<QString,QVariant> data,QString sqlWhere="");//修改
    bool delData(QString tableName,QString sqlWhere);//删除
    bool getData(QString tableName,QHash<QString,QString> &data,QString sqlWhere=""); //获取数据
    bool getData(QString tableName,QList<QHash<QString,QString>> &data,QString sqlWhere=""); //获取数据
    //获取数据
    bool getData(QString tableName,QHash<QString,QString> columndata,QList<QHash<QString,QString>> &data,QString sqlWhere=""); //获取数据
    bool queryExec(QString sqlStr);//执行sql语句，不获取结果
    bool queryExec(QString sqlStr,QList<QHash<QString,QString>> &data);//执行sql语句，并获取结果

    bool transaction();
    bool commit();
private:
    QSqlDatabase db;
    QString errorSqlText;//错误语句
private:
    void errorSql(QString sql);//错误打印
};

#endif // SERIALPORTSQLDB_H
